package com.example.ppts;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class TerceraPantalla extends Activity {
	ImageButton imgButton;
	ImageButton imgButton2;
	String elec1;
	String elec2;
	boolean TJ1 = true;
	boolean TJ2 = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tercera_pantalla);
		findViewById(R.id.piedra).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (TJ1 == true) {
					imgButton = (ImageButton) findViewById(R.id.resulJ);
					imgButton.setBackgroundResource(R.drawable.interrogacion);
					elec1 = "piedra";
					TJ2 = true;
					TJ1 = false;
				} else if (TJ2 == true) {
					imgButton2 = (ImageButton) findViewById(R.id.resulJ2);
					imgButton2.setBackgroundResource(R.drawable.piedra);
					elec2 = "piedra";
					if (elec1.equals("piedra")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.piedra);
						
					} else if (elec1.equals("papel")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.papel);
						
					} else if (elec1.equals("lagarto")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.lagarto);
						
					} else if (elec1.equals("spock")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.spock);
						
					} else {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.tijeras);

					}
					TJ2 = false;
					TJ1 = true;
					resultado();
				}
				
			}
		});

		ImageButton lag = (ImageButton) findViewById(R.id.lagarto);
		lag.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (TJ1 == true) {
					imgButton = (ImageButton) findViewById(R.id.resulJ);
					imgButton.setBackgroundResource(R.drawable.interrogacion);
					elec1 = "lagarto";
					TJ2 = true;
					TJ1 = false;
				} else if (TJ2 == true) {
					imgButton2 = (ImageButton) findViewById(R.id.resulJ2);
					imgButton2.setBackgroundResource(R.drawable.lagarto);
					elec2 = "lagarto";
					if (elec1.equals("piedra")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.piedra);
						
					} else if (elec1.equals("papel")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.papel);
						
					} else if (elec1.equals("lagarto")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.lagarto);
						
					} else if (elec1.equals("spock")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.spock);
						
					} else {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.tijeras);
						
					}
					TJ2 = false;
					TJ1 = true;
					resultado();
				}
				
			}
		});
		ImageButton sp = (ImageButton) findViewById(R.id.spock);
		sp.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (TJ1 == true) {
					imgButton = (ImageButton) findViewById(R.id.resulJ);
					imgButton.setBackgroundResource(R.drawable.interrogacion);
					elec1 = "spock";
					TJ2 = true;
					TJ1 = false;
				} else if (TJ2 == true) {
					imgButton2 = (ImageButton) findViewById(R.id.resulJ2);
					imgButton2.setBackgroundResource(R.drawable.spock);
					elec2 = "spock";
					if (elec1.equals("piedra")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.piedra);
						
					} else if (elec1.equals("papel")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.papel);
						
					} else if (elec1.equals("lagarto")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.lagarto);
						
					} else if (elec1.equals("spock")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.spock);
						
					} else {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.tijeras);
						
					}
					TJ2 = false;
					TJ1 = true;
					resultado();
				}
				
			}
		});
		ImageButton ti = (ImageButton) findViewById(R.id.tijeras);
		ti.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (TJ1 == true) {
					imgButton = (ImageButton) findViewById(R.id.resulJ);
					imgButton.setBackgroundResource(R.drawable.interrogacion);
					elec1 = "tijeras";
					TJ2 = true;
					TJ1 = false;
				} else if (TJ2 == true) {
					imgButton2 = (ImageButton) findViewById(R.id.resulJ2);
					imgButton2.setBackgroundResource(R.drawable.tijeras);
					elec2 = "tijeras";
					if (elec1.equals("piedra")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.piedra);
						
					} else if (elec1.equals("papel")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.papel);
						
					} else if (elec1.equals("lagarto")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.lagarto);
						
					} else if (elec1.equals("spock")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.spock);
						
					} else {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.tijeras);
						
					}
					TJ2 = false;
					TJ1 = true;
					resultado();
				}
				;
			}
		});
		ImageButton pa = (ImageButton) findViewById(R.id.papel);
		pa.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (TJ1 == true) {
					imgButton = (ImageButton) findViewById(R.id.resulJ);
					imgButton.setBackgroundResource(R.drawable.interrogacion);
					elec1 = "papel";
					TJ2 = true;
					TJ1 = false;
				} else if (TJ2 == true) {
					imgButton2 = (ImageButton) findViewById(R.id.resulJ2);
					imgButton2.setBackgroundResource(R.drawable.papel);
					elec2 = "papel";
					if (elec1.equals("piedra")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.piedra);
						resultado();
					} else if (elec1.equals("papel")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.papel);
						
					} else if (elec1.equals("lagarto")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.lagarto);
						
					} else if (elec1.equals("spock")) {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.spock);
						
					} else {
						imgButton = (ImageButton) findViewById(R.id.resulJ);
						imgButton.setBackgroundResource(R.drawable.tijeras);	
					}
					TJ2 = false;
					TJ1 = true;
					resultado();
				}
				
			}
		});
	}

	public void resultado() {
		if (elec1.equals("piedra") && elec2.equals("lagarto")) {
			String s="Gana el Jugador 1"+"\n";
			s+="LA PIEDRA MACHACA AL LAGARTO";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		
		} else if (elec1.equals("piedra") && elec2.equals("tijeras")) {
			String s="Gana el Jugador 1"+"\n";
			s+="LA PIEDRA ROMPE LAS TIJERAS";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("lagarto") && elec2.equals("spock")) {
			String s="Gana el Jugador 1"+"\n";
			s+="EL LAGARTO ENVENENA A SPOCK";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("lagarto") && elec2.equals("papel")) {
			String s="Gana el Jugador 1"+"\n";
			s+="EL LAGARTO ROMPE EL PAPEL";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("spock") && elec2.equals("tijeras")) {
			String s="Gana el Jugador 1"+"\n";
			s+="SPOCK ROMPE LAS TIJERAS";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("spock") && elec2.equals("piedra")) {
			String s="Gana el Jugador 1"+"\n";
			s+="sPOCK VAPORIZA LA PIEDRA";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("tijeras") && elec2.equals("lagarto")) {
			String s="Gana el Jugador 1"+"\n";
			s+="LAS TIJERAS DECAPITAN AL LAGARTO";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("tijeras") && elec2.equals("papel")) {
			String s="Gana el Jugador 1"+"\n";
			s+="LAS TIJERAS CORTAN EL PAPEL";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("papel") && elec2.equals("spock")) {
			String s="Gana el Jugador 1"+"\n";
			s+="EL PAPEL DESACREDITA A SPOCK";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("papel") && elec2.equals("piedra")) {
			String s="Gana el Jugador 1"+"\n";
			s+="EL PAPEL ENVUELVE A LA PIEDRA";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("lagarto") && elec2.equals("piedra")) {
			String s="Gana el Jugador 2"+"\n";
			s+="LA PIEDRA MACHACA AL LAGARTO";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("tijeras") && elec2.equals("piedra")) {
			String s="Gana el Jugador 2"+"\n";
			s+="LA PIEDRA ROMPE LAS TIJERAS";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("spock") && elec2.equals("lagarto")) {
			String s="Gana el Jugador 2"+"\n";
			s+="EL LAGARTO ENVENENA A SPOCK";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("papel") && elec2.equals("lagarto")) {
			String s="Gana el Jugador 2"+"\n";
			s+="EL LAGARTO SE COME EL PAPEL";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("tijeras") && elec2.equals("spock")) {
			String s="Gana el Jugador 2"+"\n";
			s+="SPOCK ROMPE LAS TIJERAS";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("piedra") && elec2.equals("spock")) {
			String s="Gana el Jugador 2"+"\n";
			s+="SPOCK VAPORIZA LA PIEDRA";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("lagarto") && elec2.equals("tijeras")) {
			String s="Gana el Jugador 2"+"\n";
			s+="LAS TIJERAS DECAPITAN AL LAGARTO";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("papel") && elec2.equals("tijeras")) {
			String s="Gana el Jugador 2"+"\n";
			s+="LAS TIJERAS CORTAN EL PAPEL";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("spock") && elec2.equals("papel")) {
			String s="Gana el Jugador 2"+"\n";
			s+="EL PAPEL DESACREDITA A SPOCK";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else if (elec1.equals("piedra") && elec2.equals("papel")) {
			String s="Gana el Jugador 2"+"\n";
			s+="EL PAPEL ENVUELVE A LA PIEDRA";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		} else {
			String s="Empate"+"\n";
			s+="NADIE GANA NI PIERDE";
			Toast toast = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT);
			toast.show();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.tercera_pantalla, menu);
		return true;
	}

}
